package com.gnote.repair.controller;

import com.alibaba.fastjson.JSON;
import com.gnote.repair.domain.EmsReportConfig;
import com.gnote.repair.domain.Response;
import com.gnote.repair.service.EmsReportConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/ReportConfig")
public class ReportConfigController {
    @Autowired
    private EmsReportConfigService service;

    @RequestMapping(value = "/getList.do", method = RequestMethod.POST)
    public String getReportConfigList(@RequestBody EmsReportConfig emsReportConfig, HttpServletRequest request) {

        List<EmsReportConfig> reportConfigList = service.getReportConfigList(emsReportConfig);
        Response<List<EmsReportConfig>> success = Response.success(reportConfigList);
        return JSON.toJSONString(success);
    }

    @RequestMapping(value = "/save.do", method = RequestMethod.POST)
    public String saveReportConfig(@RequestBody EmsReportConfig emsReportConfig, HttpServletRequest request) {
        String s = service.saveReportConfig(emsReportConfig);
        return JSON.toJSONString(Response.success(s));
    }

    @RequestMapping(value = "/delete.do", method = RequestMethod.POST)
    public String deleteReportConfig(@RequestBody EmsReportConfig emsReportConfig, HttpServletRequest request) {
        String s = service.deleteReportConfig(emsReportConfig.getRecordId());
        return JSON.toJSONString(Response.success(s));
    }

    @RequestMapping(value = "/update.do", method = RequestMethod.POST)
    String updateReportConfig(@RequestBody EmsReportConfig emsReportConfig, HttpServletRequest request) {
        String s = service.updateReportConfig(emsReportConfig);
        return JSON.toJSONString(Response.success(s));
    }

}
